package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.enterpriseregistration.LindiEnterpriseRegistrationAuditVO;
import com.minimalist.common.entity.lindi.vo.enterpriseregistration.LindiEnterpriseRegistrationQueryVO;
import com.minimalist.common.entity.lindi.vo.enterpriseregistration.LindiEnterpriseRegistrationVO;
import com.minimalist.common.feign.client.lindi.LindiEnterpriseRegistrationFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地企业注册 Feign 客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 */
@Component
public class LindiEnterpriseRegistrationFeignClientFallbackFactory extends BaseFallbackFactory<LindiEnterpriseRegistrationFeignClient> {
    private static final Logger log = LoggerFactory.getLogger(LindiEnterpriseRegistrationFeignClientFallbackFactory.class);


    @Override
    public LindiEnterpriseRegistrationFeignClient create(Throwable cause) {
        return new LindiEnterpriseRegistrationFeignClient() {
            @Override
            public R<?> addEnterpriseRegistration(LindiEnterpriseRegistrationVO enterpriseRegistrationVO) {
                logServiceUnavailable("添加企业注册信息", enterpriseRegistrationVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "添加企业注册信息失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateEnterpriseRegistrationByEnterpriseRegistrationId(LindiEnterpriseRegistrationVO enterpriseRegistrationVO) {
                logServiceUnavailable("修改企业注册信息", enterpriseRegistrationVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "修改企业注册信息失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteEnterpriseRegistrationByEnterpriseRegistrationId(Long enterpriseRegistrationId) {
                logServiceUnavailable("删除企业注册信息", enterpriseRegistrationId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "删除企业注册信息失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiEnterpriseRegistrationVO> getEnterpriseRegistrationByEnterpriseRegistrationId(Long enterpriseRegistrationId) {
                logServiceUnavailable("获取企业注册详情", enterpriseRegistrationId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "获取企业注册详情失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiEnterpriseRegistrationVO>> getPageEnterpriseRegistrationList(LindiEnterpriseRegistrationQueryVO queryVO) {
                logServiceUnavailable("分页查询企业注册信息列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "分页查询企业注册信息列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> auditEnterpriseRegistration(LindiEnterpriseRegistrationAuditVO auditVO) {
                logServiceUnavailable("审核企业注册信息", auditVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "审核企业注册信息失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}
